package cn.wolfcode.wolf2w.business.controller;

import cn.wolfcode.wolf2w.business.api.domain.Destination;
import cn.wolfcode.wolf2w.business.api.domain.Region;
import cn.wolfcode.wolf2w.business.query.DestinationQuery;
import cn.wolfcode.wolf2w.business.service.IRegionService;
import cn.wolfcode.wolf2w.common.core.constant.SecurityConstants;
import cn.wolfcode.wolf2w.common.core.domain.R;
import cn.wolfcode.wolf2w.common.security.annotation.InnerAuth;
import cn.wolfcode.wolf2w.business.service.IDestinationService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 目的地 Controller
 * 
 * @author fang
 * @date 2024-09-27
 */
@RestController
@RequestMapping("destinations")
public class DestinationController {
    @Autowired
    private IDestinationService destinationService;

    @Autowired
    private IRegionService regionService;
    /**
     * 目的地详情
     */
    @GetMapping("/detail/{id}")
    public R<Destination> detail(@PathVariable Long id) {
        Destination destination = destinationService.getById(id);
        return R.ok(destination);
    }
    /**
     * 目的地 列表
     */
    @GetMapping("/query")
    public R<IPage<Destination>> query(DestinationQuery qo) {
        IPage<Destination> page = destinationService.queryPage(qo);
        return R.ok(page);
    }
    @GetMapping("/regions")
    public R<List<Region>> regions(Integer ishot){
        List<Region> list = regionService.regions(ishot);
        return R.ok(list);

    }
    @GetMapping("/search")
    public R<List<Destination>> search(Long regionId){
        List<Destination> list = destinationService.search(regionId);
        return R.ok(list);
    }

    @GetMapping("/toasts")
    public R<List<Destination>> toasts(Long destId){
        List<Destination> list = destinationService.toasts(destId);
        return R.ok(list);

    }


    /*****************************************对外暴露Fegin接口**********************************************/
    /**
     * Feign 接口
     */
    @GetMapping("/feign/list")
    public R<List<Destination>> feignList() {
        return R.ok(destinationService.list());
    }
    @InnerAuth
    @GetMapping("/feign/{id}")
    public R<Destination> feignGet(@PathVariable Long id) {
        return R.ok(destinationService.getById(id));
    }



    @GetMapping("/feign/toasts/{id}")
    public R<List<Destination>> getToasts(@PathVariable("id") Long id, @RequestHeader(SecurityConstants.FROM_SOURCE) String source){
        List<Destination> toasts = destinationService.toasts(id);
        return R.ok(toasts);
    }

}
